package test4;

import java.util.Scanner;

public class StringDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int money;
        while (true) {
            System.out.println("请输入一个七位数以内的正整数");
            money = sc.nextInt();
            if (money > 999999999||money < 0) {
                System.out.println("输入了非法数据,请重新输入");
                continue;
            }
            break;
        }
        transNum(money);
    }
    public static void transNum(int money) {
        String transMoney = CapitalNum(money);
        transMoney = addNum(transMoney);
        System.out.println(finishNum(transMoney));
    }

    public static String CapitalNum(int money) {
        String[] cap = new String[]{"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
        String CapitalNumArray = "" ;
        for (int i = 0,count = 0,index = 0; i < 7; i++) {
            index = money % 10;
            CapitalNumArray = cap[index] + CapitalNumArray ;
            money /= 10;
            count++;
            if (money == 0) {
                break;
            }
        }
        return CapitalNumArray;
    }
    public static String addNum(String money) {
        String AllMoney = money ;
        for (int i = 0; i < 7-money.length(); i++) {
            AllMoney = "零" + AllMoney ;
        }
        return AllMoney;
    }
    public static String finishNum(String money) {
        String finishNum = "";
        String[] level = {"佰","拾","万","仟","佰","拾","元"};
        for (int i = 0; i < 7; i++) {
            finishNum += money.charAt(i);
            finishNum += level[i];
        }
        return finishNum;
    }
}
